/**
* 获取结果列表
*/
<template>
  <div>
    <!-- 面包屑导航 -->
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item :to="{ path: '/taskManage/taskList' }">任务管理</el-breadcrumb-item>
      <el-breadcrumb-item>执行结果</el-breadcrumb-item>
    </el-breadcrumb>
    <div style="padding:5px;color:#000000;text-align: center;font-family:PingFang SC;font-size:30px">执行结果列表</div>
    <el-form :inline="true" :model="formInline" class="user-search">
      <!--el-form-item label="">
        <el-input size="small" @keyup.enter="getSearchPage"  v-model="formInline.id" placeholder="输入任务ID"></el-input>
      </el-form-item>-->
      <el-form-item>
        <template slot-scope="scope">
          <!--<el-button size="small"  v-if="false" type="primary" icon="el-icon-search" @click="getSearchPage">搜索</el-button>
         -->
          <el-button size="mini" type="primary" @click="continueAction(formInline.id)">继续执行</el-button>
          <el-button size="mini" type="danger"  @click="resAction(formInline.id)">清空并重新执行</el-button>
        </template>
      </el-form-item>
    </el-form>




    <el-table size="small" @selection-change="selectChange" :data="res" highlight-current-row v-loading="loading" border element-loading-text="拼命加载中" style="margin-top:20px;width: 100%;">

      <el-table-column v-if="false" align="center" type="selection" width="50">
      </el-table-column>
      <el-table-column align="center"sortable prop="taskId" v-if="false" label="任务ID" width="100">
      </el-table-column>
      <el-table-column align="center" sortable prop="id" v-if="false"label="结果ID" width="100">
      </el-table-column>
      <!--<el-table-column :data="taskData" align="center" prop="taskName" label="任务名称" width="200">
      </el-table-column>-->
      <el-table-column align="center" prop="result" label="结果" width="600">
      </el-table-column>

      <!-- 编辑界面 -->



      <el-table-column align="center" label="操作" min-width="200">
        <template slot-scope="scope">
          <el-button size="mini" type="success" @click="resDetails(scope.row.id,scope.row.taskId)">查看详情</el-button>
          <el-button size="mini" type="danger" @click="editResult(scope.row.id, scope.row.result)">修改结果</el-button>
        </template>
      </el-table-column>

    </el-table>
    <!-- 操作 -->
    <el-dialog :title="title" :visible.sync="editFormVisible" width="50%" @click='closeDialog("edit")'>
      <el-form label-width="200px" ref="editForm" :model="editForm">
        <el-form-item label="结果内容" prop="result">


          <div style="padding:7px">

            <el-input
              type="textarea"
              :rows="15"
              v-model="editForm.result"
              placeholder="result">
            </el-input>
          </div>

        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="small" @click='closeDialog("edit")'>取消</el-button>
        <el-button size="small" type="primary" :loading="loading" class="title" @click="submitForm('editForm')">保存</el-button>
      </div>
    </el-dialog>
    <!-- 分页组件 -->

    <Pagination v-bind:child-msg="pageparm" @callFather="callFather"></Pagination>



  </div>
</template>

<script>
  // 导入请求方法

  import Pagination from '../../components/Pagination'
  import axios from "axios";
  export default {
    data() {
      return {

        obj:[{id:'',taskName:""}],

        loading: false, //是显示加载
        title: '修改结果',
        editFormVisible: false, //控制编辑页面显示与隐藏
        editForm:{
          id: '',
          result:'',
        },
        // 请求数据参数
        formInline: {
          id:this.$route.query.id,
          page: 1,
          limit: 10,
          sourceType:this.$route.query.sourceType

        },
        //任务数据
        taskData:[],

        // 文件内容
        fileContent:[],
        //结果数据
        res:[],
        // 分页参数
        pageparm: {
          currentPage: 1,
          pageSize: 10,
          total: 10
        }
      }
    },
    // 注册组件
    components: {
      Pagination
    },

    /**
     * 创建完毕
     */
    created() {
      this.getSearchPage()


    },

    /**
     * 里面的方法只有被调用才会执行
     */
    methods: {

      // 获取数据方法
      getSearchPage() {
        this.logining = true
        let url = this.$global.javaUrl + "/task/resultPageList"
        let config = {
          headers:
            {
              //'Content-Type':'application/json',
              'user' : localStorage.getItem('userId')
            },
          params: {
            pageNum:this.formInline.page,
            pageSize:this.formInline.limit,
            taskId:this.formInline.id
            //isLock: this.formInline.isLock
          }
        }

        axios.get(url, config).then(response=>{

            this.res = []
            this.res = response.data.data.rows

          this.pageparm.total = response.data.data.records

        })

      },
      // 分页插件事件
      callFather(parm) {
        this.formInline.page = parm.currentPage
        this.formInline.limit = parm.pageSize
        this.getSearchPage()
      },

      // 重新执行
      resAction(id) {
        let url = this.$global.javaUrl + "/task/resActionNow"
        let config = {
          headers:
            {
              'Content-Type':'application/json',
              'user' : localStorage.getItem('userId')
            },
          params:{'taskId':id}

        }

        this.$confirm('确定要重新执行吗?', '信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            this.loading = true;
            // 删除
            axios.get(url,config)
              .then(res => {
                if (res.data.data !=null) {
                  this.loading = false;
                  this.$message({

                    type: 'success',
                    message: '程序执行成功!'
                  })
                  this.getSearchPage()
                } else {
                  this.$message({
                    type: 'info',
                    message: "1111"
                  })
                }
              })
              .catch(err => {
                this.loading = false
                this.$message.error('程序执行失败，请稍后再试！')
              })
            this.getSearchPage()
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消清空！'
            })
          })
      },

      // 继续执行
      continueAction(id) {
        let url = this.$global.javaUrl + "/task/continueActionNow"
        let config = {
          headers:
            {
              'Content-Type':'application/json',
              'user' : localStorage.getItem('userId')
            },
          params:{'taskId':id}

        }

        this.$confirm('确定要继续执行吗?', '信息', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        })
          .then(() => {
            // 删除
            this.loading = false;
            axios.get(url,config)
              .then(res => {
                if (res.data.data !=null) {
                  this.loading = false;
                  this.$message({

                    type: 'success',
                    message: '程序执行成功!'
                  })
                  this.getSearchPage()
                } else {
                  this.$message({
                    type: 'info',
                    message: "1111"
                  })
                }
              })
              .catch(err => {
                this.loading = false
                this.$message.error('程序执行失败，请稍后再试！')
              })
            this.getSearchPage()
          })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消执行！'
            })
          })
      },
      // 查看执行结果
      resDetails(id,taskId){
        // 跳转到查询执行结果页面
        this.$router.push({path:'resultDetails',query:{resultId:id,id:taskId,sourceType:this.$route.query.sourceType}});
        //this.$router.push({path:'/resultDetails',query:{id:id}});
      },
      // 分页插件事件
      // callFather(parm) {
      //   this.formInline.page = parm.currentPage
      //   this.formInline.limit = parm.pageSize
      //   this.getSearchPage()
      // },
      //显示编辑界面
      editResult(id,result) {
        this.editFormVisible = true
          this.title = '修改结果'
          this.editForm.id = id
        this.editForm.result = result

      },
      // 编辑、添加提交方法
      submitForm(editData) {
        let config = {
          headers:
            {
              'Content-Type':'application/json',
              'user' : localStorage.getItem('userId')
            },

        }
        this.$refs[editData].validate(valid => {
          if (valid) {
            // 请求方法
            axios
              .post(this.$global.javaUrl + "/task/updateResult",this.editForm,config)
              .then(res => {
                this.editFormVisible = false
                this.loading = false
                this.pageparm.currentPage = this.formInline.page
                this.pageparm.pageSize = this.formInline.limit
                this.pageparm.total = res.data.data.records
                if (res.data.data != null) {
                  this.$message({
                    type: 'success',
                    message: "数据保存成功！"
                  })
                  this.getSearchPage()
                } else {
                  this.$message({
                    type: 'info',
                    message: res.msg
                  })
                }
              })
              .catch(err => {
                this.editFormVisible = false
                this.loading = false
                this.$message.error('保存失败，请稍后再试！')
              })
          } else {
            return false
          }
        })
      },

      // 关闭编辑、增加弹出框
      closeDialog(dialog) {
        if (dialog == 'edit') {
          this.editFormVisible = false
        } else if (dialog == 'perm') {
          this.dataAccessshow = false
        } else if (dialog == 'unit') {
          this.unitAccessshow = false
        }
      },
    }
  }
</script>

<style scoped>
  .user-search {
    margin-top: 20px;
  }
  .userRole {
    width: 100%;
  }
</style>

